from tortoise.models import Model
from tortoise import fields
########################
#####   文章相关模型   ###
########################

class Article(Model):
    class Meta:
        table = 'for_article'
    id  = fields.IntField(pk=True)
    title = fields.CharField(max_length=155, description="标题")
    category_id = fields.IntField(description="分类ID")
    created_at = fields.IntField(auto_now_add=True, description="创建时间")
    updated_at = fields.DateField(auto_now=True, description="更新时间")
    content = fields.TextField(description="内容")
    status = fields.CharField(max_length=2,description="状态")
    keywords = fields.CharField(max_length=255,description="关键字")
    thumbnail = fields.CharField(max_length=255,description="缩略图")
    sort = fields.IntField(description="排序")
    appid= fields.CharField(max_length=255,description="所属app")
    cateigory_name = ""
    # relations = fields.ReverseRelation["ArticleRelation"]

class ArticleCategory(Model):
    class Meta:
        table = 'for_article_category'
    id = fields.IntField(pk=True)
    category_name = fields.CharField(max_length=55,description="分类名称")
    sub_name = fields.CharField(max_length=255,description="副标题")
    thumbnail = fields.CharField(max_length=255,description="缩略图")
    status = fields.CharField(max_length=2,description="状态")
    sort = fields.IntField(description="排序")

class ArticleRelation(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="用户id")
    type = fields.IntField(description="类型")#1平台发布2用户发布
    # articles = fields.ForeignKeyField("article_model.Article",related_name="article_relation")
    # categories = fields.ForeignKeyField("article_model.ArticleCategory",related_name="article_category_relation")